package com.zoer.presentation.drug;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.zoer.commons.presentation.BaseAction;
import com.zoer.domain.Node;
import com.zoer.domain.view.SearchResult;
import com.zoer.hibdao.NodeDAO;

public class LoadMenuTreeAction extends BaseAction {

	private static final long serialVersionUID = -7218237421073961774L;
	private SearchResult<Node> results = new SearchResult<Node>();

	private final int YAODIAN = 1;
	private final int CHUFANGJI = 2;
	private final int HELI = 3;
	private final int JIBING = 4;
	private final int XITONGGUANLI = 5;

	@SuppressWarnings("unchecked")
	public void listyaodian() throws Exception {
		List<Node> nodelist = ((NodeDAO) getBean("nodeDao"))
				.findBySys(this.YAODIAN);
		this.results.setStatisticsList(nodelist);
		JSONObject jsonObject = JSONObject.fromObject(this.results);
		HttpServletResponse res = ServletActionContext.getResponse();
		res.setCharacterEncoding("UTF-8");
		res.getWriter().print(jsonObject.toString());
	}

	@SuppressWarnings("unchecked")
	public void listchufangji() throws Exception {
		List<Node> nodelist = ((NodeDAO) getBean("nodeDao"))
				.findBySys(this.CHUFANGJI);
		this.results.setStatisticsList(nodelist);
		JSONObject jsonObject = JSONObject.fromObject(this.results);
		HttpServletResponse res = ServletActionContext.getResponse();
		res.setCharacterEncoding("UTF-8");
		res.getWriter().print(jsonObject.toString());
	}

	@SuppressWarnings("unchecked")
	public void listheli() throws Exception {
		List<Node> nodelist = ((NodeDAO) getBean("nodeDao"))
				.findBySys(this.HELI);
		this.results.setStatisticsList(nodelist);
		JSONObject jsonObject = JSONObject.fromObject(this.results);
		HttpServletResponse res = ServletActionContext.getResponse();
		res.setCharacterEncoding("UTF-8");
		res.getWriter().print(jsonObject.toString());
	}

	@SuppressWarnings("unchecked")
	public void listjibing() throws Exception {
		List<Node> nodelist = ((NodeDAO) getBean("nodeDao"))
				.findBySys(this.JIBING);
		this.results.setStatisticsList(nodelist);
		JSONObject jsonObject = JSONObject.fromObject(this.results);
		HttpServletResponse res = ServletActionContext.getResponse();
		res.setCharacterEncoding("UTF-8");
		res.getWriter().print(jsonObject.toString());
	}

	@SuppressWarnings("unchecked")
	public void listxitongguanli() throws Exception {
		List<Node> nodelist = ((NodeDAO) getBean("nodeDao"))
				.findBySys(this.XITONGGUANLI);
		this.results.setStatisticsList(nodelist);
		JSONObject jsonObject = JSONObject.fromObject(this.results);
		HttpServletResponse res = ServletActionContext.getResponse();
		res.setCharacterEncoding("UTF-8");
		res.getWriter().print(jsonObject.toString());
	}

	public SearchResult<Node> getResults() {
		return results;
	}

	public void setResults(SearchResult<Node> results) {
		this.results = results;
	}
}